package com.lc.pianostudent.fragment;

import android.Manifest;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lc.pianostudent.BaseApplication;
import com.lc.pianostudent.R;
import com.lc.pianostudent.activity.CircleImageActivity;
import com.lc.pianostudent.activity.CircleTextActivity;
import com.lc.pianostudent.activity.ContactDetailActivity;
import com.lc.pianostudent.activity.ContactDetailItemActivity;
import com.lc.pianostudent.activity.DegreeIntroduceActivity;
import com.lc.pianostudent.activity.MyRankActivity;
import com.lc.pianostudent.activity.PersonInfoActivity;
import com.lc.pianostudent.activity.ShopActivity;
import com.lc.pianostudent.adapter.FindAdapter;
import com.lc.pianostudent.adapter.HomeNewsAdapter;
import com.lc.pianostudent.bean.CircleBean;
import com.lc.pianostudent.bean.CommentConfig;
import com.lc.pianostudent.bean.CommentsBean;
import com.lc.pianostudent.bean.FindBean;
import com.lc.pianostudent.bean.HomeNewsBean;
import com.lc.pianostudent.bean.Post;
import com.lc.pianostudent.bean.User;
import com.lc.pianostudent.conn.PostCircleDelect;
import com.lc.pianostudent.conn.PostCircleIndex;
import com.lc.pianostudent.conn.PostCircleIndexTwo;
import com.lc.pianostudent.conn.PostComment;
import com.lc.pianostudent.conn.PostGetuser;
import com.lc.pianostudent.conn.PostMailXingka;
import com.lc.pianostudent.conn.PostUploadUp;
import com.lc.pianostudent.dialog.DelectDialog;
import com.lc.pianostudent.dialog.PictureDialog;
import com.lc.pianostudent.dialog.ShopDialog;
import com.lc.pianostudent.util.KeyboardUtility;
import com.lc.pianostudent.util.PictureUtil;
import com.lc.pianostudent.util.SystemUtil;
import com.lc.pianostudent.util.Util;
import com.lc.pianostudent.view.ScrollLinearLayoutManager;
import com.lc.pianostudent.view.SelectPopupWindow;
import com.lc.pianostudent.view.SoftKeyBoardListener;
import com.lc.pianostudent.view.TakePhotoView;
import com.lc.pianostudent.view.TextEditTextView;
import com.lc.pianostudent.widget.NineGridLayoutView;
import com.lidong.photopicker.PhotoPickerActivity;
import com.lidong.photopicker.PhotoPreviewActivity;
import com.lidong.photopicker.SelectModel;
import com.lidong.photopicker.intent.PhotoPickerIntent;
import com.squareup.picasso.Picasso;
import com.zcx.helper.app.AppCallBack;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.permission.PermissionsActivity;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

import static android.app.Activity.RESULT_OK;
import static android.widget.LinearLayout.VERTICAL;

/**
 * Created by Administrator on 2018/4/18.
 */

public class FindFragment extends BasePictureFragment implements View.OnClickListener{
    private List<User> findList = new ArrayList<>();
    private List<CircleBean.ListBean> findList1 = new ArrayList<>();
    private List<Post> postList = new ArrayList<>();
    private static final int REQUEST_CAMERA_CODE = 10;

    @BoundView(value = R.id.xingka_main,isClick = true) private LinearLayout xingka_main;
    @BoundView(R.id.sv_search_result) private NestedScrollView nestedScrollView;
    @BoundView(R.id.find_recycle_view) private RecyclerView find_recycle_view;
    private FindAdapter findAdapter;
    @BoundView(value = R.id.camera,isClick = true) private TakePhotoView camera;
    private ArrayList<String> imagePaths = new ArrayList<>();
    @BoundView(value = R.id.my_rank_layout,isClick = true) private LinearLayout my_rank_layout;
    @BoundView(value = R.id.degree_layout,isClick = true) private LinearLayout degree_layout;
    @BoundView(R.id.name) private TextView name;
    @BoundView(R.id.person) private TextView person;
    @BoundView(R.id.wealth) private TextView wealth;
    @BoundView(R.id.fenshu) private TextView fenshu;
    @BoundView(R.id.nianji) private TextView nianji;
    @BoundView(R.id.jishu) private TextView jishu;
    @BoundView(R.id.jingyan) private TextView jingyan;

    @BoundView(R.id.xing_one) private ImageView xing_one;
    @BoundView(R.id.xing_two) private ImageView xing_two;
    @BoundView(R.id.xing_three) private ImageView xing_three;
    @BoundView(R.id.xing_four) private ImageView xing_four;
    @BoundView(R.id.xing_five) private ImageView xing_five;
    @BoundView(R.id.xing_six) private ImageView xing_six;
    @BoundView(R.id.xing_seven) private ImageView xing_seven;
    @BoundView(R.id.xing_eight) private ImageView xing_eight;
    @BoundView(R.id.xing_nine) private ImageView xing_nine;
    @BoundView(R.id.xing_ten) private ImageView xing_ten;
    @BoundView(R.id.xing_eleven) private ImageView xing_eleven;
    @BoundView(R.id.xing_twelve) private ImageView xing_twelve;
    @BoundView(value = R.id.xing_one_layout,isClick = true) private LinearLayout xing_one_layout;
    @BoundView(value = R.id.xing_two_layout,isClick = true) private LinearLayout xing_two_layout;
    @BoundView(R.id.bodyLayout) private RelativeLayout bodyLayout;
    private int currentKeyboardH;// 当前软键盘的高度
    private int screenHeight; // 当前屏幕高度
    private int editTextBodyHeight; // 当前输入框的高度

    private CommentConfig commentConfig;
    @BoundView(R.id.comment_et)
    private EditText editText;
    @BoundView(R.id.editTextBodyLl)
    private LinearLayout editTextBody;
    @BoundView(value = R.id.comment_send,isClick = true)
    private Button comment_send;
    private int circle_position;
    private int comment_position_int;
    private boolean isFirst = true;
    private boolean isShuaxin = true;
    private int dianzan_position;
    private String current_caozuo;
    @BoundView(R.id.hair) private ImageView hair;
    @BoundView(R.id.shoe) private ImageView shoe;
    @BoundView(R.id.jacket) private ImageView jacket;
    @BoundView(R.id.access) private ImageView access;
    @BoundView(R.id.suit) private ImageView suit;
    @BoundView(R.id.download) private ImageView download;
    @BoundView(R.id.maozi) private ImageView maozi;
    @BoundView(R.id.shoutao) private ImageView shoutao;
    @BoundView(R.id.wazi) private ImageView wazi;
    @BoundView(R.id.xianglian) private ImageView xianglian;
    @BoundView(R.id.erhuan) private ImageView erhuan;
    @BoundView(R.id.yanjing) private ImageView yanjing;
    @BoundView(R.id.mianshi) private ImageView mianshi;
    @BoundView(R.id.luomo) private ImageView luomo;
    @BoundView(R.id.biaoqing) private ImageView biaoqing;
    private SelectPopupWindow menuWindow;
    private String xinghao = "";
    private int degree_int = 0;
    private Bitmap bitmap;

    private  String num = "";  //星卡数量
    //星卡点击看大图
    public PostMailXingka postMailXingka = new PostMailXingka(new AsyCallBack<PostMailXingka.PostMailXingkaInfo>(){

        @Override
        public void onSuccess(String toast, int type, Object o, PostMailXingka.PostMailXingkaInfo postMailXingkaInfo) throws Exception {
            menuWindow = new SelectPopupWindow(getActivity(),postMailXingkaInfo.imgList,0);
            //显示窗口 //设置layout在PopupWindow中显示的位置
            menuWindow.showAtLocation(xing_one_layout, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        }

        @Override
        public void onFail(String toast, int type) throws Exception {
            UtilToast.show(toast);
        }
    });
    //点赞接口
    public PostUploadUp postUploadUp = new PostUploadUp(new AsyCallBack<PostUploadUp.PostUploadUpInfo>(){

        @Override
        public void onSuccess(String toast, int type, Object o, PostUploadUp.PostUploadUpInfo postUploadUpInfo) throws Exception {
//            UtilToast.show(toast);
            isFirst = false;
            current_caozuo = "dianzan";
            postCircleIndexTwe.user_id = BaseApplication.BasePreferences.readUID();
            postCircleIndexTwe.type = "0";
            postCircleIndexTwe.execute(false,0);

        }

        @Override
        public void onFail(String toast, int type) throws Exception {
            UtilToast.show(toast);
        }
    });
    //评论接口
    public PostComment postComment = new PostComment(new AsyCallBack<PostComment.PostCommentInfo>(){

        @Override
        public void onSuccess(String toast, int type, Object o, PostComment.PostCommentInfo postCommentInfo) throws Exception {
            updateAddComment();
            updateEditTextBodyVisible(View.GONE, null);

        }

        @Override
        public void onFail(String toast, int type) throws Exception {
            UtilToast.show(toast);
        }
    });


    //删除状态接口
    public PostCircleDelect postCircleDelect = new PostCircleDelect(new AsyCallBack<PostCircleDelect.PostCircleDelectInfo>(){

        @Override
        public void onSuccess(String toast, int type, Object o, PostCircleDelect.PostCircleDelectInfo postCircleDelectInfo) throws Exception {

            postCircleIndexTwe.user_id = BaseApplication.BasePreferences.readUID();
            postCircleIndexTwe.type = "0";
            postCircleIndexTwe.execute(false,0);
        }

        @Override
        public void onFail(String toast, int type) throws Exception {
            UtilToast.show(toast);
        }
    });
//    朋友圈接口
    private PostCircleIndexTwo postCircleIndexTwe = new PostCircleIndexTwo(new AsyCallBack<CircleBean>(){
        @Override
        public void onSuccess(String toast, int type, Object o, CircleBean circleBean) throws Exception {
            name.setText(circleBean.getUser().getName()+"( "+circleBean.getUser().getCname()+" )");
            person.setText(circleBean.getUser().getPerson());
            Log.e("===wea",circleBean.getUser().getWealth()+"===jy");
            wealth.setText(circleBean.getUser().getWealth()+"");
            fenshu.setText(circleBean.getUser().getDegree()+"");
            nianji.setText("( "+circleBean.getUser().getXuewei()+" )");
            jishu.setText(circleBean.getUser().getGrade()+"");
            jingyan.setText("( "+circleBean.getUser().getExper()+" )");
            num = circleBean.getUser().getNum()+"";
            if((circleBean.getUser().getNum()+"").equals("0")){
                xing_one_layout.setVisibility(View.INVISIBLE);
                xing_two_layout.setVisibility(View.INVISIBLE);
            }else if((circleBean.getUser().getNum()+"").equals("1")){
                xing_one_layout.setVisibility(View.VISIBLE);
                xing_one.setVisibility(View.VISIBLE);
                xing_two.setVisibility(View.INVISIBLE);
                xing_three.setVisibility(View.INVISIBLE);
                xing_four.setVisibility(View.INVISIBLE);
                xing_five.setVisibility(View.INVISIBLE);
                xing_six.setVisibility(View.INVISIBLE);
                xing_two_layout.setVisibility(View.INVISIBLE);
            }else if((circleBean.getUser().getNum()+"").equals("2")){
                xing_one_layout.setVisibility(View.VISIBLE);
                xing_one.setVisibility(View.VISIBLE);
                xing_two.setVisibility(View.VISIBLE);
                xing_three.setVisibility(View.INVISIBLE);
                xing_four.setVisibility(View.INVISIBLE);
                xing_five.setVisibility(View.INVISIBLE);
                xing_six.setVisibility(View.INVISIBLE);
                xing_two_layout.setVisibility(View.INVISIBLE);
            }else if((circleBean.getUser().getNum()+"").equals("3")){
                xing_one_layout.setVisibility(View.VISIBLE);
                xing_one.setVisibility(View.VISIBLE);
                xing_two.setVisibility(View.VISIBLE);
                xing_three.setVisibility(View.VISIBLE);
                xing_four.setVisibility(View.INVISIBLE);
                xing_five.setVisibility(View.INVISIBLE);
                xing_six.setVisibility(View.INVISIBLE);
                xing_two_layout.setVisibility(View.INVISIBLE);
            }else if((circleBean.getUser().getNum()+"").equals("4")){
                xing_one_layout.setVisibility(View.VISIBLE);
                xing_one.setVisibility(View.VISIBLE);
                xing_two.setVisibility(View.VISIBLE);
                xing_three.setVisibility(View.VISIBLE);
                xing_four.setVisibility(View.VISIBLE);
                xing_five.setVisibility(View.INVISIBLE);
                xing_six.setVisibility(View.INVISIBLE);
                xing_two_layout.setVisibility(View.INVISIBLE);
            }else if((circleBean.getUser().getNum()+"").equals("5")){
                xing_one_layout.setVisibility(View.VISIBLE);
                xing_one.setVisibility(View.VISIBLE);
                xing_two.setVisibility(View.VISIBLE);
                xing_three.setVisibility(View.VISIBLE);
                xing_four.setVisibility(View.VISIBLE);
                xing_five.setVisibility(View.VISIBLE);
                xing_six.setVisibility(View.INVISIBLE);
                xing_two_layout.setVisibility(View.INVISIBLE);
            }else if((circleBean.getUser().getNum()+"").equals("6")){
                xing_one_layout.setVisibility(View.VISIBLE);

                xing_two_layout.setVisibility(View.INVISIBLE);
            }else if((circleBean.getUser().getNum()+"").equals("7")){
                xing_one_layout.setVisibility(View.VISIBLE);
                xing_two_layout.setVisibility(View.VISIBLE);
                xing_seven.setVisibility(View.VISIBLE);
                xing_eight.setVisibility(View.INVISIBLE);
                xing_nine.setVisibility(View.INVISIBLE);
                xing_ten.setVisibility(View.INVISIBLE);
                xing_eleven.setVisibility(View.INVISIBLE);
                xing_twelve.setVisibility(View.INVISIBLE);
            }else if((circleBean.getUser().getNum()+"").equals("8")){
                xing_one_layout.setVisibility(View.VISIBLE);
                xing_two_layout.setVisibility(View.VISIBLE);
                xing_seven.setVisibility(View.VISIBLE);
                xing_eight.setVisibility(View.VISIBLE);
                xing_nine.setVisibility(View.INVISIBLE);
                xing_ten.setVisibility(View.INVISIBLE);
                xing_eleven.setVisibility(View.INVISIBLE);
                xing_twelve.setVisibility(View.INVISIBLE);
            }else if((circleBean.getUser().getNum()+"").equals("9")){
                xing_one_layout.setVisibility(View.VISIBLE);
                xing_two_layout.setVisibility(View.VISIBLE);
                xing_seven.setVisibility(View.VISIBLE);
                xing_eight.setVisibility(View.VISIBLE);
                xing_nine.setVisibility(View.VISIBLE);
                xing_ten.setVisibility(View.INVISIBLE);
                xing_eleven.setVisibility(View.INVISIBLE);
                xing_twelve.setVisibility(View.INVISIBLE);
            }else if((circleBean.getUser().getNum()+"").equals("10")){
                xing_one_layout.setVisibility(View.VISIBLE);
                xing_two_layout.setVisibility(View.VISIBLE);
                xing_seven.setVisibility(View.VISIBLE);
                xing_eight.setVisibility(View.VISIBLE);
                xing_nine.setVisibility(View.VISIBLE);
                xing_ten.setVisibility(View.VISIBLE);
                xing_eleven.setVisibility(View.INVISIBLE);
                xing_twelve.setVisibility(View.INVISIBLE);
            }else if((circleBean.getUser().getNum()+"").equals("11")){
                xing_one_layout.setVisibility(View.VISIBLE);
                xing_two_layout.setVisibility(View.VISIBLE);
                xing_seven.setVisibility(View.VISIBLE);
                xing_eight.setVisibility(View.VISIBLE);
                xing_nine.setVisibility(View.VISIBLE);
                xing_ten.setVisibility(View.VISIBLE);
                xing_eleven.setVisibility(View.VISIBLE);
                xing_twelve.setVisibility(View.INVISIBLE);
            }else if((circleBean.getUser().getNum()+"").equals("12")){
                xing_one_layout.setVisibility(View.VISIBLE);
                xing_two_layout.setVisibility(View.VISIBLE);

            }
            Log.e("-----",circleBean.getMote()+"====");
            Picasso.with(getContext()).load(circleBean.getMote()).into(luomo);

            //头发
            if((circleBean.getHair().getId()+"").equals("")){
                hair.setVisibility(View.INVISIBLE);
            }else {
                hair.setVisibility(View.VISIBLE);
//                GlideLoader.getInstance().get(circleBean.getHair().getPicurl(),hair);
                Picasso.with(getContext()).load(circleBean.getHair().getPicurl()).into(hair);
            }
            //上身
            if((circleBean.getJack().getId()+"").equals("")){
                jacket.setVisibility(View.INVISIBLE);
            }else {
                jacket.setVisibility(View.VISIBLE);
//                GlideLoader.getInstance().get(circleBean.getJack().getPicurl(),jacket);
                Picasso.with(getContext()).load(circleBean.getJack().getPicurl()).into(jacket);

            }
            //下装
            if((circleBean.getDownload().getId()+"").equals("")){
                download.setVisibility(View.INVISIBLE);
            }else {
                download.setVisibility(View.VISIBLE);
//                GlideLoader.getInstance().get(circleBean.getDownload().getPicurl(),download);
                Picasso.with(getContext()).load(circleBean.getDownload().getPicurl()).into(download);

            }

            //表情
            if((circleBean.getExpression().getId()+"").equals("")){
                biaoqing.setVisibility(View.INVISIBLE);
            }else {
                biaoqing.setVisibility(View.VISIBLE);
//                GlideLoader.getInstance().get(circleBean.getDownload().getPicurl(),download);
                Picasso.with(getContext()).load(circleBean.getExpression().getPicurl()).into(biaoqing);

            }
            //配饰
            if(circleBean.getAccess().size() == 0){
                access.setVisibility(View.INVISIBLE);
                maozi.setVisibility(View.INVISIBLE);
                erhuan.setVisibility(View.INVISIBLE);
                wazi.setVisibility(View.INVISIBLE);
                yanjing.setVisibility(View.INVISIBLE);
                shoutao.setVisibility(View.INVISIBLE);
                mianshi.setVisibility(View.INVISIBLE);
                xianglian.setVisibility(View.INVISIBLE);
            }else {
                for(int i = 0;i<circleBean.getAccess().size();i++){


                    if((circleBean.getAccess().get(i).getType()+"").equals("14")){  //手套
                        shoutao.setVisibility(View.VISIBLE);
                        Picasso.with(getContext()).load(circleBean.getAccess().get(i).getPicurl()).into(shoutao);

//                        GlideLoader.getInstance().get(postGoodsCheckInfo.accessShowList.get(i).getPicurl(),shoutao);

                    }else
                    if((circleBean.getAccess().get(i).getType()+"").equals("13")){  //包
                        access.setVisibility(View.VISIBLE);
//                        GlideLoader.getInstance().get(postGoodsCheckInfo.accessShowList.get(i).getPicurl(),access);
                        Picasso.with(getContext()).load(circleBean.getAccess().get(i).getPicurl()).into(access);
                    }else
                    if((circleBean.getAccess().get(i).getType()+"").equals("12")){  //耳环
                        erhuan.setVisibility(View.VISIBLE);
//                        GlideLoader.getInstance().get(postGoodsCheckInfo.accessShowList.get(i).getPicurl(),erhuan);
                        Picasso.with(getContext()).load(circleBean.getAccess().get(i).getPicurl()).into(erhuan);

                    }else

                    if((circleBean.getAccess().get(i).getType()+"").equals("16")){  //袜子
                        wazi.setVisibility(View.VISIBLE);
//                        GlideLoader.getInstance().get(postGoodsCheckInfo.accessShowList.get(i).getPicurl(),wazi);
                        Picasso.with(getContext()).load(circleBean.getAccess().get(i).getPicurl()).into(wazi);

                    }else
                    if((circleBean.getAccess().get(i).getType()+"").equals("18")){  //眼睛
                        yanjing.setVisibility(View.VISIBLE);
//                        GlideLoader.getInstance().get(postGoodsCheckInfo.accessShowList.get(i).getPicurl(),yanjing);
                        Picasso.with(getContext()).load(circleBean.getAccess().get(i).getPicurl()).into(yanjing);

                    }else
                    if((circleBean.getAccess().get(i).getType()+"").equals("19")){  //帽子
                        maozi.setVisibility(View.VISIBLE);
//                        GlideLoader.getInstance().get(postGoodsCheckInfo.accessShowList.get(i).getPicurl(),maozi);
                        Picasso.with(getContext()).load(circleBean.getAccess().get(i).getPicurl()).into(maozi);

                    }else
                    if((circleBean.getAccess().get(i).getType()+"").equals("20")){  //面饰
                        mianshi.setVisibility(View.VISIBLE);
//                        GlideLoader.getInstance().get(postGoodsCheckInfo.accessShowList.get(i).getPicurl(),mianshi);
                        Picasso.with(getContext()).load(circleBean.getAccess().get(i).getPicurl()).into(mianshi);

                    } else
                    if((circleBean.getAccess().get(i).getType()+"").equals("21")){  //项链
                        xianglian.setVisibility(View.VISIBLE);
//                        GlideLoader.getInstance().get(postGoodsCheckInfo.accessShowList.get(i).getPicurl(),xianglian);
                        Picasso.with(getContext()).load(circleBean.getAccess().get(i).getPicurl()).into(xianglian);

                    }
                }


            }
            //鞋子
            if((circleBean.getShose().getId()+"").equals("")){
                shoe.setVisibility(View.INVISIBLE);
            }else {
                shoe.setVisibility(View.VISIBLE);
//                GlideLoader.getInstance().get(circleBean.getShose().getPicurl(),shoe);
                Picasso.with(getContext()).load(circleBean.getShose().getPicurl()).into(shoe);

            }
            //套装
            if((circleBean.getSuit().getId()+"").equals("")){
                suit.setVisibility(View.INVISIBLE);
            }else {
                suit.setVisibility(View.VISIBLE);
//                GlideLoader.getInstance().get(circleBean.getSuit().getPicurl(),suit);
                Picasso.with(getContext()).load(circleBean.getSuit().getPicurl()).into(suit);

            }


            if(type == 0){
                findList1.clear();
            }
            findList1.addAll(circleBean.getList());

            //第一次进入朋友圈，加载全部数据  不是第一次，说明是点赞或者评论  只加载一条数据
            if(isFirst ){
                if(isShuaxin){  //真正第一次进入
                    Log.e("=====jy",isShuaxin+"===");
                    findAdapter.notifyDataSetChanged();
                    isShuaxin = false;
                }else {   //刷新
                    Log.e("=====jy",isShuaxin+"===");
                    findAdapter. notifyItemRangeChanged(0, findList1.size());
                }
            }else {
                if(current_caozuo.equals("dianzan")){
                    findAdapter.notifyItemChanged(dianzan_position, 0);
                }else {
                    findAdapter.notifyItemChanged(circle_position, 0);
                }

            }



        }

        @Override
        public void onEnd(String toast, int type) throws Exception {
//            recyclerView.refreshComplete();
//            recyclerView.loadMoreComplete();
        }

        @Override
        public void onFail(String toast, int type) throws Exception {
            UtilToast.show(toast);
        }
    });


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = BoundViewHelper.boundView(this, inflater.inflate(R.layout.fragment_find, null));

        initView();
        return  view;
    }

    private void initView(){

        setAppCallBack(new CallBack());
        showSystemParameter();

        setViewTreeObserver();


        ScrollLinearLayoutManager scrollLinearLayoutManager = new ScrollLinearLayoutManager(getContext());
        scrollLinearLayoutManager.setSmoothScrollbarEnabled(true);
        scrollLinearLayoutManager.setAutoMeasureEnabled(true);
        scrollLinearLayoutManager.setOrientation(VERTICAL);
        find_recycle_view.setLayoutManager(scrollLinearLayoutManager);
        find_recycle_view.setHasFixedSize(true);
        find_recycle_view.setItemAnimator(null);
        find_recycle_view.setNestedScrollingEnabled(false);
        findAdapter = new FindAdapter(getActivity(), findList1);
        find_recycle_view.setAdapter(findAdapter);


        postCircleIndexTwe.user_id = BaseApplication.BasePreferences.readUID();
        postCircleIndexTwe.type = "0";
        postCircleIndexTwe.execute();

        //图文
        camera.setShortClickListener(new TakePhotoView.OnTakePhotoClickListener() {
            @Override
            public void onClick() {
                action();
            }
        });

        //纯文字
        camera.setLongClickListener(new TakePhotoView.OnLongTakePhotoClickListener() {
            @Override
            public void onLongClick() {
                startVerifyActivity(CircleTextActivity.class);
            }
        });

        //点赞
        findAdapter.setOnItemDianzanClickListener(new FindAdapter.OnItemDianzanClickListener() {
            @Override
            public void onItemDianzanClick(View view, int position) {

                dianzan_position = position;
                if((findList1.get(position).getUp()+"").equals("2")){
                    postUploadUp.up = "2";

                }else {
                    postUploadUp.up = "1";
                }

                postUploadUp.id = findList1.get(position).getPostid()+"";
                postUploadUp.user_id = BaseApplication.BasePreferences.readUID();

                postUploadUp.execute();
            }
        });

        //主评论
        findAdapter.setOnItemZhuCommentClickListener(new FindAdapter.OnItemZhuCommentClickListener() {
            @Override
            public void onItemZhuCommentClick(View view, int position) {
                circle_position = position;
                CommentConfig config = new CommentConfig();
                config.commentType = CommentConfig.Type.PUBLIC;
                config.circlePosition =position;
                onItemButtonClick(config);
            }
        });

        //附评论

        findAdapter.setOnItemCommentClickListener(new FindAdapter.OnItemCommentClickListener() {
            @Override
            public void onItemCommentClick(View view, int position, int comment_posi, List<CommentsBean> comment) {

                if(BaseApplication.BasePreferences.readUID().equals(comment.get(comment_posi).getUserid())){
                    UtilToast.show("不能回复自己哦~");
                }else {
                    circle_position= position;
                    comment_position_int = comment_posi;
//                    UtilToast.show("=="+comment_posi);
                    CommentConfig config = new CommentConfig();
                    config.commentType = CommentConfig.Type.REPLY;
                    config.commentPosition = comment_posi;
                    config.replyUser =comment.get(comment_posi);
                    onItemButtonClick(config);
                }

            }
        });

//        layout_nine_grid.setOnItemImageClickListener(new NineGridLayoutView.OnItemImageClickListener() {
//            @Override
//            public void onItemImageClick(int position, List<String> img) {
//                Log.e("====",position+"==="+img.get(position)+"===");
//                menuWindow = new SelectPopupWindow(ContactDetailItemActivity.this,img,position);
//                //显示窗口 //设置layout在PopupWindow中显示的位置
//                menuWindow.showAtLocation(album_time, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
//            }
//        });

//        删除状态

        findAdapter.setOnItemDelectClickListener(new FindAdapter.OnItemDelectClickListener() {
            @Override
            public void onItemDelectClick(View view, final int zhuangtai_position) {
//                删除弹窗
                new DelectDialog(getContext(), R.layout.dialog_delect) {
                    @Override
                    public void cancel() {
                        dismiss();
                    }

                    @Override
                    public void confirm() {

                        postCircleDelect.id =findList1.get(zhuangtai_position).getPostid()+"";
                        postCircleDelect.execute(getContext(),false);

                    }
                }.show();

            }
        });
        //点击评论  这时滑动recycleview 输入框消失
        nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                if (scrollY > oldScrollY) {
                    // 向下滑动
                    updateEditTextBodyVisible(View.GONE, null);
                    editText.setText("");
                }

                if (scrollY < oldScrollY) {
                    // 向上滑动
                    updateEditTextBodyVisible(View.GONE, null);
                    editText.setText("");
                }

                if (scrollY == 0) {
                    // 顶部
                }

                if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
                    // 底部
                }
            }

        });

        SoftKeyBoardListener.setListener(getActivity(), new SoftKeyBoardListener.OnSoftKeyBoardChangeListener() {
            @Override
            public void keyBoardShow(int height) {

            }

            @Override
            public void keyBoardHide(int height) {
                updateEditTextBodyVisible(View.GONE, null);
                editText.setText("");

            }
        });
    }



    private void action(){
        PermissionsActivity.StartActivity(new String[]{Manifest.permission.CAMERA}, new PermissionsActivity.PermissionsCallBack() {

            @Override
            public void onSuccess() {

                new PictureDialog(getContext()){

                    @Override
                    public void onAlbum() {

                        PhotoPickerIntent intent = new PhotoPickerIntent(getContext());
                        intent.setSelectModel(SelectModel.MULTI);
                        intent.setShowCarema(false); // 是否显示拍照
                        intent.setMaxTotal(6);
                        intent.setSelect(imagePaths.size());// 最多选择照片数量，默认为6
                        intent.setSelectedPaths(imagePaths); // 已选中的照片地址， 用于回显选中状态
                        startActivityForResult(intent, REQUEST_CAMERA_CODE);
                        dismiss();

                    }

                    @Override
                    public void onCamera() {

                        startCamera(null);
                        dismiss();
                    }

                }.show();

            }

        });
    }

    @Override
    protected void resultPhotoPath(ImageView imageView, String s) {
//        ArrayList<String> list = new ArrayList<>();
//        if(xinghao.equals("samsung")){
//            degree_int =  Util.readPictureDegree(s);
//
//
//            Matrix matrix = new Matrix();
//            matrix.postRotate(+degree_int); /*翻转90度*/
//            int width = PictureUtil.getimage(s).getWidth();
//            int height =PictureUtil.getimage(s).getHeight();
//            bitmap = Bitmap.createBitmap(PictureUtil.getimage(s), 0, 0, width, height, matrix, true);
//            String path_ys = PictureUtil.saveBitmap(getContext(), PictureUtil.compressImage(bitmap));
//            list.add(path_ys);
//            CircleImageActivity.StartActivity(list);
//        }else {
//
////        String path_ys = PictureUtil.saveBitmap(getContext(), PictureUtil.getSmallBitmap(s));
//            String path_ys = PictureUtil.saveBitmap(getContext(), PictureUtil.compressImage(bitmap));
//            list.add(path_ys);
//            CircleImageActivity.StartActivity(list);
//        }



        ArrayList<String> list = new ArrayList<>();
        degree_int =  Util.readPictureDegree(s);
        bitmap = Util.toturn(PictureUtil.getimage(s),degree_int);
        String path_ys = PictureUtil.saveBitmap(getContext(), PictureUtil.compressImage(bitmap));
        list.add(path_ys);
        CircleImageActivity.StartActivity(list);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == RESULT_OK) {
            switch (requestCode) {
                // 选择照片
                case REQUEST_CAMERA_CODE:
                    ArrayList<String> list = data.getStringArrayListExtra(PhotoPickerActivity.EXTRA_RESULT);
                    ArrayList<String> sasuo_list = new ArrayList<>();
                    for(int i = 0;i<list.size();i++){
                        degree_int =  Util.readPictureDegree(list.get(i));
                        bitmap = Util.toturn(PictureUtil.getimage(list.get(i)),degree_int);
                        String path_ys = PictureUtil.saveBitmap(getContext(), PictureUtil.compressImage(bitmap));
                        sasuo_list.add(path_ys);
                    }
                    if(list.size() != 0){
                        list.clear();
                    }

                    list.addAll(sasuo_list);
                    CircleImageActivity.StartActivity(list);

                    break;


            }
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.my_rank_layout:   //我的等级
                startVerifyActivity(MyRankActivity.class);
                break;

            case R.id.degree_layout:   //学位
                startVerifyActivity(DegreeIntroduceActivity.class);
                break;

            case R.id.comment_send:  //评论发送
                String content = editText.getText().toString().trim();
                if (TextUtils.isEmpty(content)) {
                    Toast.makeText(getContext(), "评论内容不能为空...", Toast.LENGTH_SHORT).show();
                    return;
                }
                if(commentConfig.commentType == CommentConfig.Type.PUBLIC){
                    postComment.type = "1";
                    postComment.fromid = "";
                }else if(commentConfig.commentType == CommentConfig.Type.REPLY){
                    CommentsBean commentsBean = findList1.get(circle_position).getComment().get(comment_position_int);

                    postComment.type = "2";
                    postComment.fromid = commentsBean.getId();
                }

                postComment.id = findList1.get(circle_position).getPostid()+"";
////                postComment.user_id = BaseApplication.BasePreferences.readUID();
                postComment.user_id = BaseApplication.BasePreferences.readUID();;
                postComment.content  = content;
                postComment.execute();

                break;

            case R.id.xing_one_layout:  //星卡点击看大图
                if(num.equals("0")){

                }else {
                    postMailXingka.num = num;
                    postMailXingka.execute(getContext(),false);
                }

                break;

            case R.id.xing_two_layout:  //星卡点击看大图
                if(num.equals("0")){

                }else {
                    postMailXingka.num = num;
                    postMailXingka.execute(getContext(),false);
                }
                break;
        }
    }

    public class CallBack implements AppCallBack {

        public void onRefresh() {
            isFirst = true;
            postCircleIndexTwe.user_id = BaseApplication.BasePreferences.readUID();
            postCircleIndexTwe.type = "0";
            postCircleIndexTwe.execute(false,0);

        }

    }
    public void updateAddComment() {
        isFirst = false;
        current_caozuo = "pinglun";
        postCircleIndexTwe.user_id = BaseApplication.BasePreferences.readUID();
        postCircleIndexTwe.type = "0";
        postCircleIndexTwe.execute(false,0);
        //清空评论文本
        this.editText.setText("");
    }
    private void onItemButtonClick(CommentConfig config){

        commentConfig = config;
        if (commentConfig.commentType == CommentConfig.Type.REPLY) {
            editText.setHint("回复" + commentConfig.replyUser.getName() + ":");
        }else {
            editText.setHint("说几句吧...");
        }
        this.updateEditTextBodyVisible(View.VISIBLE, commentConfig);
    }

    public void updateEditTextBodyVisible(int visibility, CommentConfig config) {
        this.commentConfig = config;
        this.editTextBody.setVisibility(visibility);
        // 计算偏移量
//        this.measureCircleItemHighAndCommentItemOffset(commentConfig);
        if (View.VISIBLE == visibility) {
            editText.requestFocus();
            //弹出键盘
            KeyboardUtility.showSoftInput(editText.getContext(), editText);
        } else if (View.GONE == visibility) {
            //隐藏键盘
            KeyboardUtility.hideSoftInput(editText.getContext(), editText);
        }
    }

//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
//            if (editTextBody != null && editTextBody.getVisibility() == View.VISIBLE) {
//                updateEditTextBodyVisible(View.GONE, null);
//                return true;
//            }
//        }
//        return super.onKeyDown(keyCode, event);
//    }
    //输入框收回
    private void setViewTreeObserver() {

        final ViewTreeObserver swipeRefreshLayoutVTO = bodyLayout.getViewTreeObserver();
        swipeRefreshLayoutVTO.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Rect r = new Rect();
                bodyLayout.getWindowVisibleDisplayFrame(r);
                int statusBarH = getStatusBarHeight();//状态栏高度
                int screenH = bodyLayout.getRootView().getHeight();
                if (r.top != statusBarH) {
                    //在这个demo中r.top代表的是状态栏高度，在沉浸式状态栏时r.top＝0，通过getStatusBarHeight获取状态栏高度
                    r.top = statusBarH;
                }
                int keyboardH = screenH - (r.bottom - r.top);
//                Log.d(TAG, "screenH＝ " + screenH + " &keyboardH = " + keyboardH + " &r.bottom=" + r.bottom + " &top=" + r.top + " &statusBarH=" + statusBarH);

                if (keyboardH == currentKeyboardH) {//有变化时才处理，否则会陷入死循环
                    return;
                }
                currentKeyboardH = keyboardH;
                screenHeight = screenH;//应用屏幕的高度
                editTextBodyHeight = editTextBody.getHeight();

                if (keyboardH < 150) {//说明是隐藏键盘的情况
                    updateEditTextBodyVisible(View.GONE, null);
                    return;
                }

            }
        });
    }

    private int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }
    private void showSystemParameter() {
        String TAG = "系统参数：";
        Log.e(TAG, "手机厂商：" + SystemUtil.getDeviceBrand());
        Log.e(TAG, "手机型号：" + SystemUtil.getSystemModel());
        Log.e(TAG, "手机当前系统语言：" + SystemUtil.getSystemLanguage());
        Log.e(TAG, "Android系统版本号：" + SystemUtil.getSystemVersion());
        xinghao = SystemUtil.getDeviceBrand();
    }

}
